package com.atguigu.lease.common.exceptions;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author zhaolingqiao
 * @CreateTime 2024/12/10
 * descritpion:全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(LeaseException.class)
    public Result<Object> leaseExceptionHandler(LeaseException e){
        e.printStackTrace();
        return Result.build(e.getCode(),e.getMessage());
    }
    /**
     * todo:逻辑：定义保底异常处理器，处理Exception异常
     *      如出现异常，其他异常处理器都不能处理，则使用保底异常处理器执行
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result<Object> exceptionHandler(Exception e){
        e.printStackTrace();
        Result<Object> fail = Result.fail();
        return fail;
    }
}
